const Controller=require('egg').Controller;
class Session extends Controller{
    async index(){
        if(this.ctx.session.name){
            await this.ctx.render('session')
        }else{
            this.ctx.redirect('/session/login')
        }
    }
    async post(){
        let data=this.ctx.request.body;
        console.log(data);
        if(data.text=='admin'&&data.password=='123'){
            this.ctx.session.name=(data.text)
            this.ctx.redirect('/session');
        }else{
            await this.ctx.render('sessionlogin',{
                text:['错误']
            })
        }
    }
    async login(){
        await this.ctx.render('sessionlogin')
    }
    async loginout(){
        this.ctx.session.name='';
        this.ctx.redirect('/session/login');
    }
}
module.exports=Session;